package master.ghrm.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Version;

import org.hibernate.annotations.ForeignKey;

@Entity
public class Evaluator extends AbstractBaseEntity {

	private static final long serialVersionUID = 1L;

	/**
	 * private static final String[] EXCLUDE_ATTR = new String[] { "assessments", "interviews" };
	 **/

	@Version
	private Long version;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "evaluator_id")
	private Integer evaluatorId;

	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "profile_id")
	@ForeignKey(name = "FKEVALUATOR_PROFILEID")
	private Profile profile;

	@OneToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST }, fetch = FetchType.LAZY, mappedBy = "evaluator")
	private List<Assessment> assessments = new ArrayList<Assessment>();

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "tbl_evaluation_evaluator", joinColumns = { @JoinColumn(name = "evaluator_id", nullable = true, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "evaluation_id", nullable = true, updatable = true) })
	@ForeignKey(name = "FKEVALUATOR_INTERVIEWS", inverseName = "FKINTERVIEWS_EVALUATOR")
	private List<Evaluation> interviews = new ArrayList<Evaluation>();

	/**
	 * Default constructor, persistence use.
	 */
	public Evaluator() {
	}

	/**
	 * @param aProfile user doing the evaluation.
	 */
	public Evaluator(Profile aProfile) {
		this.profile = aProfile;
	}

	/**
	 * @return ID.
	 */
	public Integer getEvaluatorId() {
		return evaluatorId;
	}

	/**
	 * @param anEvaluatorId ID.
	 */
	public void setEvaluatorId(Integer anEvaluatorId) {
		this.evaluatorId = anEvaluatorId;
	}

	/**
	 * Persistence use.
	 * 
	 * @return entity version.
	 */
	public Long getVersion() {
		return version;
	}

	/**
	 * Persistence use.
	 * 
	 * @param aVersion entity version.
	 */
	public void setVersion(Long aVersion) {
		this.version = aVersion;
	}

	/**
	 * @return number of assessments.
	 */
	public Integer getNbOfAssessments() {
		return assessments.size();
	}

	/**
	 * @return assessments of this evaluator.
	 */
	public List<Assessment> getAssessments() {
		return assessments;
	}

	/**
	 * @param assessmentList assessments.
	 */
	public void setAssessments(List<Assessment> assessmentList) {
		this.assessments = assessmentList;
	}

	/**
	 * Add assessment.
	 * 
	 * @param assessment assessment.
	 */
	public void addAssessment(Assessment assessment) {
		assessments.add(assessment);
	}

	/**
	 * @return user.
	 */
	public Profile getProfile() {
		return profile;
	}

	/**
	 * @param aProfile user.
	 */
	public void setProfile(Profile aProfile) {
		this.profile = aProfile;
	}

	/**
	 * @return interviews.
	 */
	public List<Evaluation> getInterviews() {
		return interviews;
	}

	/**
	 * @param interviewList interviews.
	 */
	public void setInterviews(List<Evaluation> interviewList) {
		this.interviews = interviewList;
	}

	/**
	 * @see com.levi9.hrm.model.base.AbstractBaseEntity#getExcludedAttributes()
	 */
	@Override
	protected String[] getExcludedAttributes() {
		return new String[] { "assessments", "interviews" };
	}

}
